unit frmServiceSelector;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,
  uServices
  ;

type
  TfrmSelectService = class(TForm)
    ServiceListBox: TListBox;
    OKButton: TButton;
    CancelButton: TButton;
    procedure ServiceListBoxClick(Sender: TObject);
    procedure ServiceListBoxDblClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

{var
  frmSelectService: TfrmSelectService;}

Function SelectService( aParentForm : TForm; const aService : String ) : CServiceProviderInformation;

implementation

{$R *.DFM}

Function SelectService;
Var D : TfrmSelectService;
    I : Integer;
    S : TList;
Begin
  Result := nil;

  S := ServiceManager.Services( aService );

  D := TfrmSelectService.Create( aParentForm );
  try
    With D do
      Begin
        Top := aParentForm.Top + ((aParentForm.Height-Height) div 2);
        Left := aParentForm.Left + ((aParentForm.Width-Width) div 2);

        With ServiceListBox do
          For I := 0 to Pred( S.Count ) do
            Items.Add( CServiceProviderInformation( S.Items[I] ).Visual );
      End;

    If D.ShowModal = mrOK
      then Result := CServiceProviderInformation( S.Items[ D.ServiceListbox.ItemIndex ] );
  finally
    If Assigned( S ) then S.Free;
    If Assigned( D ) then D.Free;
  end;
End;

procedure TfrmSelectService.ServiceListBoxClick(Sender: TObject);
begin
  OKButton.Enabled := ServiceListbox.ItemIndex >= 0;
end;

procedure TfrmSelectService.ServiceListBoxDblClick(Sender: TObject);
begin
  If OKButton.Enabled
    then OKButton.Click;
end;

end.
